package com.example.models.misc;

import android.view.VelocityTracker;

import com.example.models.Tower;
import com.example.models.Unit;
import com.example.util.Figure;
import com.example.util.FigureType;
import com.example.util.Vec2D;

public class Shot extends Figure {
	
	private Unit shotDestination;
	private Tower shootingTower;
	
	public Shot (Tower tower, Unit shotDestination) {
		super();
		setFigureType(FigureType.Shot);
		setName(tower.getShotName());
		setVelocity(tower.getShotVelocity());
		this.shotDestination = shotDestination;
		this.shootingTower = tower;
		setPosition(tower.getX(), tower.getY());
		Vec2D direction = new Vec2D (shotDestination.getX() - this.getX(),shotDestination.getY() - this.getY());
		direction.normalize();
		setDirection(direction);
	}
	
	public void setShotDestination(Unit shotDestination) {
		this.shotDestination = shotDestination;
	}
	
	public Unit getShotDestination() {
		return shotDestination;
	}
	
	public void update () {
		Vec2D direction = new Vec2D (shotDestination.getX() - this.getX(),shotDestination.getY() - this.getY());
		direction.normalize();
		setDirection(direction);
		setPosition(this.getX() + this.getVelocity() * getDirection().getX(), this.getY() + this.getVelocity() * getDirection().getY());
	}

	public void setShootingTower(Tower shootingTower) {
		this.shootingTower = shootingTower;
	}

	public Tower getShootingTower() {
		return shootingTower;
	}
}
